package com.hspedu.newData.dmsxl.栈;

import org.junit.Test;

import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-28 
 * @Version: 1.0
 */

public class LC225用队列实现栈 {

    class MyStack {

        Queue<Integer> list1; //出队
        Queue<Integer> list2; //入队

        public MyStack() {
            list1 = new ArrayDeque<>();
            list2 = new ArrayDeque<>();
        }

        public void push(int x) {
           list2.offer(x);
           while(!list1.isEmpty()){
               list2.offer(list1.poll());
           }
           Queue<Integer> temp = list1;
           list1 = list2;
           list2 = temp;
        }

        public int pop() {
            return  list1.poll();
        }

        public int top() {
            return list1.peek();
        }

        public boolean empty() {
            return list1.isEmpty() && list2.isEmpty();
        }
    }

    @Test
    public void test() {
        // 测试代码

    }
}
